package hk.polyu;

import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import java.io.*;
import java.net.URL;

public class MapPanel extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4955081488587131409L;
	private Image 		mImage;
	private String		mPath = "hk/polyu/image/8x8grid.jpg";

    public MapPanel() {
       try {
    	   ClassLoader cl = this.getClass().getClassLoader();  
    	   URL iconURL = cl.getResource(mPath);
    	   mImage = ImageIO.read(iconURL).getScaledInstance(800, 800, Image.SCALE_DEFAULT);;
       } catch (IOException ex) {
            ex.printStackTrace();
       }
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        // scale and draw.
        //Dimension d = this.getSize();
        //g.drawImage(mImage, 0, 0, d.width, d.height, null);
        g.drawImage(mImage, 0, 0, mImage.getWidth(null), mImage.getHeight(null), null);
        this.drawAnchor(g);
    }
    
    
    private void drawAnchor(Graphics g) {
    	
    	for(Point p: Setting.instance().mAnchorList) {
    		g.fillOval(p.x, p.y, 20, 20);
    	}
    }
    
    public void drawLoc(Point p) {
    	
    	
    	Graphics g = this.getGraphics();
    	//this.paintComponent(g);
    	
    	g.setColor(Color.RED);
    	
    	g.fillOval(p.x, p.y, 20, 20);
    	
    }

}
